package com.lyj.dao.impl;

import java.sql.ResultSet;

import com.lyj.dao.RecordDao;
import com.lyj.pojo.Record;
import com.lyj.pojo.RecordQueryModel;
import com.lyj.util.base.BaseDaoImpl;
import com.lyj.util.base.BaseQueryModel;

/**
 * 
 * @author 李艺江
 * @version 创建时间：2018年12月18日 下午6:50:27
 */

public class RecordDaoImpl extends BaseDaoImpl implements RecordDao {

	@Override
	public String getInsertSql(Object data) {
		Record record = (Record) data;
		return "insert into t_record(subjectId,optionId,userId)" + "values(" + record.getSubjectId() + ","
				+ record.getOptionId() + "," + record.getUserId() + ")";
	}

	@Override
	public String getUpdateSql(Object data) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getDeleteSql(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String getFindAllSql() {
		return null;
	}

	@Override
	public String getFindConditionSql(BaseQueryModel queryModel) {
		RecordQueryModel qm = (RecordQueryModel) queryModel;
		StringBuilder sb=new StringBuilder();
		sb.append("select * from t_record ");
		sb.append(" where 1=1 ");
		if(qm.getOptionId() != null && qm.getOptionId() > 0) {
			sb.append(" and optionId=" + qm.getOptionId());
		}
		if(qm.getSubjectId() != null && qm.getSubjectId() > 0) {
			sb.append(" and subjectId=" + qm.getSubjectId());
		}
		if(qm.getUserId() != null && qm.getUserId() > 0) {
			sb.append(" and userId=" + qm.getUserId());
		}
		return sb.toString();
	}

	@Override
	public Object rsToObject(ResultSet rs) throws Exception {
		Record record = new Record();
		record.setID(rs.getLong("id"));
		record.setSubjectId(rs.getLong("subjectId"));
		record.setOptionId(rs.getLong("optionId"));
		record.setUserId(rs.getLong("userId"));
		return record;
	}

}
